package cn.bandeqing.store.controller;

import cn.bandeqing.base.resp.Resp;
import cn.bandeqing.base.resp.Table;
import cn.bandeqing.finance.resp.LabelValue;
import cn.bandeqing.finance.resp.LabelValueStr;
import cn.bandeqing.store.req.StoreSaveOrUpdateReq;
import cn.bandeqing.store.req.StoreSelectReq;
import cn.bandeqing.store.req.StoreTableReq;
import cn.bandeqing.store.req.StoreUserSelectReq;
import cn.bandeqing.store.resp.StoreTable;
import cn.bandeqing.store.rpc.IStoreRpc;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/store")
@RestController
@Tag(name = "门店")
public class StoreController {

    @DubboReference
    private IStoreRpc storeRpc;

    @Operation(summary = "selectDoyin")
    @PostMapping("/selectDoyin")
    public Resp<List<LabelValueStr>> selectDoyin(@RequestBody @Valid StoreSelectReq req) {
        return storeRpc.selectDoyin(req);
    }

    @Operation(summary = "select")
    @PostMapping("/select")
    public Resp<List<LabelValue>> select(@RequestBody @Valid StoreSelectReq req) {
        return storeRpc.select(req);
    }

    @Operation(summary = "userSelect")
    @PostMapping("/userSelect")
    public Resp<List<LabelValue>> userSelect(@RequestBody @Valid StoreUserSelectReq req) {
        return storeRpc.userSelect(req);
    }

    @Operation(summary = "表格")
    @PostMapping("/table")
    public Resp<Table<StoreTable>> table(@RequestBody @Valid StoreTableReq req) {
        return storeRpc.table(req);
    }

    @Operation(summary = "创建或更新")
    @PostMapping("/saveOrUpdate")
    public Resp<Void> saveOrUpdate(@RequestBody @Valid StoreSaveOrUpdateReq req) {
        storeRpc.saveOrUpdate(req);
        return Resp.success();
    }

}
